**********************************************************************************
**** Replication Data for: State-Building, Collective Efficacy, and the Co-Production of Public Goods in Rural Africa
*** Authors: Natalie Letsa and Martha Wilfahrt
** Journal: Comparative Political Studies
* File Date: 18 December 2025
**********************************************************************************

cd "~/Letsa_Wilfahrt_CPS_Replication Files/"

****** FIGURE D1: Relationship between average perceived collective efficacy and average satisfaction with the village as a place to live
{
use "Datasets/Original_Survey.dta", clear

revrs Q46
rename revQ46 satisfiedvillage

collapse (first) Togo  (mean) CollectiveEfficacy_Factor2  satisfiedvillage , by(Village)

label define satisfied 4 "Extremely Satisfied" 3 "Somewhat Satisfied" 2 "Somewhat Disatisfied" 1 "Disatisfied"
label values satisfiedvillage satisfied

twoway (scatter satisfiedvillage CollectiveEfficacy_Factor2) (lfit satisfiedvillage CollectiveEfficacy_Factor2, lpattern(solid)), ///
	ytitle("") ylabel(2(1)4, valuelabel)  xtitle("Average Collective Efficacy Factor") legend(order(1 "Avg Village Satisfaction" 2 "Fitted Values"))
}

****** TABLE E1: Assessing the Relationship between Residing in Togo and Potential Alternative Mechanisms
{
use "Datasets/Original_Survey.dta", clear

gen Cultural_ID_First = 0
replace Cultural_ID_First = 1 if Q27 == 3 
replace Cultural_ID_First = 1 if Q27 == 6

rename Q30 Ethnic_over_Natl

logit Cultural_ID_First Togo Age   Education HH_SES IndEfficacy_Factor H6bpopulationest, robust cluster(Village)
	est sto CultureID
	estadd local  C  "Yes"
reg Ethnic_over_Natl Togo Age   Education HH_SES IndEfficacy_Factor H6bpopulationest, robust cluster(Village)
	est sto EthnicNatl
	estadd local  C  "Yes"

esttab CultureID EthnicNatl  using "Tables Output/TableE1.tex", replace /// ///
	scalars("C Controls") se b(3) star(** 0.05 *** 0.001) ///
    title("Assessing the Relationship between Residing in Togo and Potential Alternative Mechanisms") ///
	   mlabels("Cultural Identity #1" "Co-ethnic over Co-National") 
}
	
****** TABLE E2: Assessing the Relationship between Residing in Togo and Collective Efficacy Controlling for Potential Alternative Mechanisms
{
use "Datasets/Original_Survey.dta", clear

gen Cultural_ID_First = 0
replace Cultural_ID_First = 1 if Q27 == 3 
replace Cultural_ID_First = 1 if Q27 == 6

rename Q30 Ethnic_over_Natl

reg CollectiveEfficacy_Factor Togo Cultural_ID_First Age   Education HH_SES IndEfficacy_Factor H6bpopulationest, robust cluster(Village)
	est sto CE_CulturalID
	estadd local  OLS  "Yes"
	estadd local  Ch  "No"
	estadd local  C  "Yes"
	
reg CollectiveEfficacy_Factor Togo Ethnic_over_Natl Age   Education HH_SES IndEfficacy_Factor H6bpopulationest, robust cluster(Village)
	est sto CE_EthnicNatl
	estadd local  OLS  "Yes"
	estadd local  Ch  "No"
	estadd local  C  "Yes"
	
rename Q83 Coll_Eff1
rename Q84 Coll_Eff2
rename CollectiveEfficacy_Factor2 Coll_Eff3

reshape long Coll_Eff, i(InstanceID) j(item)
tab item, gen(i)
rename i3 self1

for var Cultural_ID_First Ethnic_over_Natl  Age    Education Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest: gen s_X1 = self1*X

gen vign1 = 1-self1
eq het: vign1 self1

constraint def 1 [lns1]self1=0

* Cultural ID #1
eq thresh: Age  Education Togo  Cultural_ID_First   HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest 

gllamm Coll_Eff s_Togo1 s_Cultural_ID_First1    s_Age1  s_Education21 s_HH_SES1  s_IndEfficacy_Factor1 s_H6bpopulationest1 i1 i2 , robust /*
*/ i(InstanceID) link(soprobit) s(het) ethresh(thresh) constr(1) /*
*/ init
est sto CE_CulturalID_Chopit
 estadd local  OLS  "No"
 estadd local  Ch  "Yes"
 estadd local  C  "Yes"
 
* Ethnic Over National Identification
eq thresh: Age  Education Togo  Ethnic_over_Natl   HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest 

gllamm Coll_Eff s_Togo1 s_Ethnic_over_Natl1    s_Age1  s_Education21 s_HH_SES1  s_IndEfficacy_Factor1 s_H6bpopulationest1 i1 i2 , robust /*
*/ i(InstanceID) link(soprobit) s(het) ethresh(thresh) constr(1) /*
*/ init

est sto CE_EthnicNatl_Chopit
 estadd local  OLS  "No"
 estadd local  Ch  "Yes"
 estadd local  C  "Yes"

 
esttab CE_CulturalID CE_CulturalID_Chopit CE_EthnicNatl CE_EthnicNatl_Chopit   using "Tables Output/TableE2.tex", replace /// ///
	scalars("OLS OLS" "Ch CHOPIT" "C Controls") se b(3) star(** 0.05 *** 0.001) ///
	keep(Togo Ethnic_over_Natl Cultural_ID_First s_Togo1 s_Cultural_ID_First1 s_Ethnic_over_Natl1) ///
 	order(Togo s_Togo1 Ethnic_over_Natl s_Ethnic_over_Natl1 Cultural_ID_First  s_Cultural_ID_First1 ) ///
   title("TABLE E2: Assessing the Relationship between Residing in Togo and Collective Efficacy Controlling for Potential Alternative Mechanisms")
}

****** TABLE F1: Table 2 Replication; Ethnic Diversity Tests
{
use "Datasets/Original_Survey.dta", clear

bysort Village : gen N = _n
bysort Village : egen VillageSample = max(N)
drop N
bysort Village Q29: gen N = _n
bysort Village Q29: egen MaxN = max(N)
bysort Village Q29: replace MaxN = . if MaxN ! = N
bysort Village Q29: gen MaxN_perc = MaxN/VillageSample
bysort Village Q29: gen N_sq = MaxN_perc*MaxN_perc
bysort Village: egen H_Index2 = sum(N_sq)
bysort Village: gen H_Index = 1-H_Index2
drop H_Index2
rename H_Index VillageELF

revrs Q83
rename revQ83 Coll_Eff1
rename Q84 Coll_Eff2
rename CollectiveEfficacy_Factor2 Coll_Eff3

reshape long Coll_Eff, i(InstanceID) j(item)

tab item, gen(i)
rename i3 self1

for var Age VillageELF  Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex: gen s_X1 = self1*X

gen vign1 = 1-self1
eq het: vign1 self1

constraint def 1 [lns1]self1=0

eq thresh: Age VillageELF Gender Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex


gllamm Coll_Eff s_Togo1 s_VillageELF1 s_Age1  s_Education21 s_HH_SES1  s_IndEfficacy_Factor1 s_Ethnic_Minority1 s_H6bpopulationest1 s_InfrastructureIndex1 i1 i2 , robust/*
*/ i(InstanceID) link(soprobit) s(het) ethresh(thresh) constr(1) /*
*/ init

est sto CE_ELF
	estadd local  C  "Yes"
	
esttab  CE_ELF using "Tables Output/TableF1.tex", replace /// 
	keep(s_Togo1 s_VillageELF1) ///
	scalars("C Controls") wide se b(2) star(** 0.05 *** 0.001) ///
    title("TABLE F1: Table 2 Replication; Ethnic Diversity Tests")
}

****** FIGURE F1: Reported actor solving village problem in past year
{
use "Datasets/Original_Survey.dta", clear

label define WhoSolved 1 "Villagers" 2 "NGO/Donors" 3 "Local Politician" 4 "National Politicians" 5 "Bureaucrats" 6 "Chief" 7 "Big Man" 8 "No One" 
replace Vprob_WhoSolved1 = . if Vprob_WhoSolved1 == 10
replace Vprob_WhoSolved1 = . if Vprob_WhoSolved1 == 9
replace Vprob_WhoSolved1 = . if Vprob_WhoSolved1 == 8
label values Vprob_WhoSolved1 WhoSolved

histogram Vprob_WhoSolved1, frequency fcolor(gs4)  barwidth(.9) ylabel(0(20)80) ///
	xlabel(1(1)7, labels labsize(vsmall) angle(forty_five) valuelabel) ///
	by(Togo) ytitle("# Respondents") xtitle("Who Solved Village Problem?") ///
	 by(, note("") title("Figure F1: Reported actor solving village problem in past year", position(6)))
}

****** FIGURE F2: Descriptions about what has changed in village since 1980s.
{
use "Datasets/Original_Survey.dta", clear

label define Diff 1 "Rise Nuclear Family" 2 "Decline grp solidarity" 3 "Tribalism" 4 "Decline Trust" 5 "Population Increase" 6 "Laziness" 7 "Love of money" 8 "Rise Pol Divisions" 9 "Chief rivalries" 10 "Arrival outsiders" 11 "Women's rights" 12 "Other"

gen Diff1980s = .
replace Diff1980s = 1 if Why_Diff1980s == "1"
replace Diff1980s = 2 if Why_Diff1980s == "2"
replace Diff1980s = 3 if Why_Diff1980s == "3"
replace Diff1980s = 4 if Why_Diff1980s == "4"
replace Diff1980s = 5 if Why_Diff1980s == "5"
replace Diff1980s = 6 if Why_Diff1980s == "6"
replace Diff1980s = 7 if Why_Diff1980s == "7"
replace Diff1980s = 8 if Why_Diff1980s == "8"
replace Diff1980s = 9 if Why_Diff1980s == "9"
replace Diff1980s = 10 if Why_Diff1980s == "10"
replace Diff1980s = 11 if Why_Diff1980s == "11"
replace Diff1980s = 12 if Why_Diff1980s == "12"

label values Diff1980s Diff

histogram Diff1980s, discrete percent fcolor(ebblue) xlabel(0(1)1) xlabel(1(1)12, ///
	labels labsize(vsmall) angle(forty_five) valuelabel) by(Togo) xtitle("") ///
	 by(, note("") title("Changes since 1980s", position(6)))
}

****** TABLE F2: Difference of Means in Perceived Likely Assistance by Actor
{
use "Datasets/Original_Survey.dta", clear

gen Q22_Alt = Q22
replace Q22_Alt = 9 if Q22_C_1 == "Mp" | Q22_C_1 == "MP" | Q22_C_2 == "Our member of parliament" | Q22_C_2 == "Our member" | Q22_C_2 == "Member of parliament" | Q22_C_2 == "Mp" | Q22_C_2 == "DEPUTE" | Q22_C_3 == "Mp" | Q22_C_3 == "Member ofparliament" |  Q22_C_3 == "Member of parliament"
replace Q22_Alt = 8 if Q22_C_1 == "The chief" | Q22_C_1 == "Chiefs" | Q22_C_1 == "Chefs stool man" | Q22_C_1 == "CHEF CANTON" | Q22_C_3 == "CHEF VILLAGE" | Q22_C_4 == "cheif" | Q22_C_4 == "CHEF VILLAGE" | Q22_C_6 == "Chief Akpalu" | Q22_C_5 == "Our chief"  | Q22_C_5 == "cheif gbogliga lana" | Q22_C_5 == "Youth chief"
replace Q22_Alt = 7 if Q22_C_2 == "NGOs" | Q22_C_4 ==  "UNE PERSONNALITE DE L'UNESCO" | Q22_C_6 == "PLAN INTERNATIONAL TOGO" | Q22_C_5 == "RESPONSABLE D UNE ONG"
replace Q22_Alt = 6 if Q22_C_1 == "CVD" | Q22_C_4 == "LE CVD" | Q22_C_7 == "Unit  Committee and Town development comm9" | Q22_C_1 ==  "Youth leader" | Q22_C_1 == "Unit committee" | Q22_C_1 == "The unit committee  members" 
replace Q22_Alt = 5 if Q22_C_5 == "CADRES ET DIASPORA" | Q22_C_1 == "CADRE DU  VILLAGE"  | Q22_C_5 == "DIASPORA" | | Q22_C_1 == "CADRE DU  VILLAGE" | Q22_C_3 == "LES NATIFS DU VILLAGE" |Q22_C_7 == "DIASPORA" | Q22_C_7 ==  "DIASPORA DES NATIFS DU VILLAGE" | Q22_C_7 == "Our children's outside the village" | Q22_C_7 == "RESSORTISSANT DE APOTI" | Q22_C_7 == "RESSORTISSANT DU VILLAGE" | Q22_C_7 == "RESSORTISSANTS" | Q22_C_7 == "RESSORTISSANTS HORS DU VILLAGE" | Q22_C_7 == "RSSORTISSANTS"
replace Q22_Alt = 2 if Q22_C_1 == "Presedent" | Q22_C_1 == "MEMBRE DU GOUVERNEMENT" | Q22_C_5 == "LE SECRÉTARIAT DU PREMIER MINISTRE" | Q22_C_5 == "CHEF DOUANIER" | Q22_C_5 == "FONCTIONNAIRE" | Q22_C_5 == "INSPECTEUR"
replace Q22_Alt = 3 if Q22_C_1 == "Party officials" | Q22_C_5 == "Party officials"
replace Q22_Alt = 1 if Q22_C_2 == "MAIRE" | Q22_C_5 == "AUTORITES DU VILLAGE"  | Q22_C_2 == "DCE" | Q22_C_2 == "CONSEILLER MUNICIPAL" | Q22_C_2 == "Assembly men" | Q22_C_2 == "Assembly man" | Q22_C_2 == "Assembly Man" | Q22_C_2 == "Asemble man" | Q22_C_2 == "ASSEMBLY MEN" | Q22_C_3 == "LE CONSEILLER MUNICIPAL" | Q22_C_3 == "DCE" | Q22_C_3 == "ADJOINT AU MAIRE"

gen Help_LG = 0
replace Help_LG = 1 if Q19 < 3
replace Help_LG= . if Q19 == .
replace Help_LG = 1 if Q22_Alt == 1
replace Help_LG = 1 if Q22_Alt == 1

gen Help_Chief = 0
replace Help_Chief = 1 if Q21 < 3
replace Help_Chief= . if Q21 == .
replace Help_Chief = 1 if Q22_Alt == 8

gen Help_MP_Party = 0
replace Help_MP_Party = 1 if Q20 < 3
replace Help_MP_Party= . if Q20 == .
replace Help_MP_Party = 1 if Q22_Alt == 3

gen Help_CG = 0
replace Help_CG = 1 if Q22_Alt == 2
replace Help_CG = . if Q22_Alt == .

gen Help_Center = Help_MP_Party
replace Help_Center = 1 if Help_CG == 1

gen Help_CivilSoc = 0
replace Help_CivilSoc = 1 if Q22_Alt == 6 | Q22 == 7
replace Help_CivilSoc = . if Q22_Alt == .

gen Help_PrivateInd = 0
replace Help_PrivateInd = 1 if Q22_Alt == 4 | Q22_Alt == 5
replace Help_PrivateInd = . if Q22_Alt == .

gen Help_NoOne = 0
replace Help_NoOne = 1 if Q22_Alt == 8
replace Help_NoOne = . if Q22_Alt == .

ttest Help_LG, by(Togo)
ttest Help_Chief, by(Togo)
ttest Help_MP_Party, by(Togo)
ttest Help_CG, by(Togo)
ttest Help_CivilSoc, by(Togo)
ttest Help_PrivateInd, by(Togo)
ttest Help_NoOne, by(Togo)
}

****** FIGURE G1: Balance of Pretreatment Attributes for Entire Border
{
cd "~/Letsa_Wilfahrt_CPS_Replication Files/Tables Output"

use "Datasets/Geobalance_10kmGrid.dta", clear
foreach var of varlist D_Border20 D_Border21 D_Border22 D_Border23 D_Border24 D_Border25 D_Border26 D_Border27 D_Border28 D_Border29 D_Border30 D_Border31 D_Border32 D_Border33 D_Border34 D_Border35 D_Border36 D_Border37 D_Border38 D_Border39 D_Border40 D_Border41 D_Border42 D_Border43 D_Border44 D_Border45 D_Border46 D_Border47 D_Border48 D_Border49 D_Border50 D_Border1 D_Border2 D_Border3 D_Border4 D_Border5 D_Border6 D_Border7 D_Border8 D_Border9 D_Border10 D_Border11 D_Border12 D_Border13 D_Border14 D_Border15 D_Border16 D_Border17 D_Border18 D_Border19 {
	quietly ttest cec_mean if `var' == 1, by(Togo)
	gen T1`var'= r(mu_1)
	gen T2`var'= r(mu_2)
	gen T_SE_`var'= r(se)
} 

foreach var of varlist D_Border20 D_Border21 D_Border22 D_Border23 D_Border24 D_Border25 D_Border26 D_Border27 D_Border28 D_Border29 D_Border30 D_Border31 D_Border32 D_Border33 D_Border34 D_Border35 D_Border36 D_Border37 D_Border38 D_Border39 D_Border40 D_Border41 D_Border42 D_Border43 D_Border44 D_Border45 D_Border46 D_Border47 D_Border48 D_Border49 D_Border50 D_Border1 D_Border2 D_Border3 D_Border4 D_Border5 D_Border6 D_Border7 D_Border8 D_Border9 D_Border10 D_Border11 D_Border12 D_Border13 D_Border14 D_Border15 D_Border16 D_Border17 D_Border18 D_Border19 {
	gen T_Diff_`var' = T2`var'-T1`var'
	gen T_Upper_`var' = T_Diff_`var'+(T_SE_`var'*1.96)
	gen T_Lower_`var' = T_Diff_`var'-(T_SE_`var'*1.96)
} 

gen N = _n
drop if N !=1
keep N T1D_Border20 T2D_Border20 T_SE_D_Border20 T1D_Border21 T2D_Border21 T_SE_D_Border21 T1D_Border22 T2D_Border22 T_SE_D_Border22 T1D_Border23 T2D_Border23 T_SE_D_Border23 T1D_Border24 T2D_Border24 T_SE_D_Border24 T1D_Border25 T2D_Border25 T_SE_D_Border25 T1D_Border26 T2D_Border26 T_SE_D_Border26 T1D_Border27 T2D_Border27 T_SE_D_Border27 T1D_Border28 T2D_Border28 T_SE_D_Border28 T1D_Border29 T2D_Border29 T_SE_D_Border29 T1D_Border30 T2D_Border30 T_SE_D_Border30 T1D_Border31 T2D_Border31 T_SE_D_Border31 T1D_Border32 T2D_Border32 T_SE_D_Border32 T1D_Border33 T2D_Border33 T_SE_D_Border33 T1D_Border34 T2D_Border34 T_SE_D_Border34 T1D_Border35 T2D_Border35 T_SE_D_Border35 T1D_Border36 T2D_Border36 T_SE_D_Border36 T1D_Border37 T2D_Border37 T_SE_D_Border37 T1D_Border38 T2D_Border38 T_SE_D_Border38 T1D_Border39 T2D_Border39 T_SE_D_Border39 T1D_Border40 T2D_Border40 T_SE_D_Border40 T1D_Border41 T2D_Border41 T_SE_D_Border41 T1D_Border42 T2D_Border42 T_SE_D_Border42 T1D_Border43 T2D_Border43 T_SE_D_Border43 T1D_Border44 T2D_Border44 T_SE_D_Border44 T1D_Border45 T2D_Border45 T_SE_D_Border45 T1D_Border46 T2D_Border46 T_SE_D_Border46 T1D_Border47 T2D_Border47 T_SE_D_Border47 T1D_Border48 T2D_Border48 T_SE_D_Border48 T1D_Border49 T2D_Border49 T_SE_D_Border49 T1D_Border50 T2D_Border50 T_SE_D_Border50 T1D_Border1 T2D_Border1 T_SE_D_Border1 T1D_Border2 T2D_Border2 T_SE_D_Border2 T1D_Border3 T2D_Border3 T_SE_D_Border3 T1D_Border4 T2D_Border4 T_SE_D_Border4 T1D_Border5 T2D_Border5 T_SE_D_Border5 T1D_Border6 T2D_Border6 T_SE_D_Border6 T1D_Border7 T2D_Border7 T_SE_D_Border7 T1D_Border8 T2D_Border8 T_SE_D_Border8 T1D_Border9 T2D_Border9 T_SE_D_Border9 T1D_Border10 T2D_Border10 T_SE_D_Border10 T1D_Border11 T2D_Border11 T_SE_D_Border11 T1D_Border12 T2D_Border12 T_SE_D_Border12 T1D_Border13 T2D_Border13 T_SE_D_Border13 T1D_Border14 T2D_Border14 T_SE_D_Border14 T1D_Border15 T2D_Border15 T_SE_D_Border15 T1D_Border16 T2D_Border16 T_SE_D_Border16 T1D_Border17 T2D_Border17 T_SE_D_Border17 T1D_Border18 T2D_Border18 T_SE_D_Border18 T1D_Border19 T2D_Border19 T_SE_D_Border19 T_Diff_D_Border20 T_Upper_D_Border20 T_Lower_D_Border20 T_Diff_D_Border21 T_Upper_D_Border21 T_Lower_D_Border21 T_Diff_D_Border22 T_Upper_D_Border22 T_Lower_D_Border22 T_Diff_D_Border23 T_Upper_D_Border23 T_Lower_D_Border23 T_Diff_D_Border24 T_Upper_D_Border24 T_Lower_D_Border24 T_Diff_D_Border25 T_Upper_D_Border25 T_Lower_D_Border25 T_Diff_D_Border26 T_Upper_D_Border26 T_Lower_D_Border26 T_Diff_D_Border27 T_Upper_D_Border27 T_Lower_D_Border27 T_Diff_D_Border28 T_Upper_D_Border28 T_Lower_D_Border28 T_Diff_D_Border29 T_Upper_D_Border29 T_Lower_D_Border29 T_Diff_D_Border30 T_Upper_D_Border30 T_Lower_D_Border30 T_Diff_D_Border31 T_Upper_D_Border31 T_Lower_D_Border31 T_Diff_D_Border32 T_Upper_D_Border32 T_Lower_D_Border32 T_Diff_D_Border33 T_Upper_D_Border33 T_Lower_D_Border33 T_Diff_D_Border34 T_Upper_D_Border34 T_Lower_D_Border34 T_Diff_D_Border35 T_Upper_D_Border35 T_Lower_D_Border35 T_Diff_D_Border36 T_Upper_D_Border36 T_Lower_D_Border36 T_Diff_D_Border37 T_Upper_D_Border37 T_Lower_D_Border37 T_Diff_D_Border38 T_Upper_D_Border38 T_Lower_D_Border38 T_Diff_D_Border39 T_Upper_D_Border39 T_Lower_D_Border39 T_Diff_D_Border40 T_Upper_D_Border40 T_Lower_D_Border40 T_Diff_D_Border41 T_Upper_D_Border41 T_Lower_D_Border41 T_Diff_D_Border42 T_Upper_D_Border42 T_Lower_D_Border42 T_Diff_D_Border43 T_Upper_D_Border43 T_Lower_D_Border43 T_Diff_D_Border44 T_Upper_D_Border44 T_Lower_D_Border44 T_Diff_D_Border45 T_Upper_D_Border45 T_Lower_D_Border45 T_Diff_D_Border46 T_Upper_D_Border46 T_Lower_D_Border46 T_Diff_D_Border47 T_Upper_D_Border47 T_Lower_D_Border47 T_Diff_D_Border48 T_Upper_D_Border48 T_Lower_D_Border48 T_Diff_D_Border49 T_Upper_D_Border49 T_Lower_D_Border49 T_Diff_D_Border50 T_Upper_D_Border50 T_Lower_D_Border50 T_Diff_D_Border1 T_Upper_D_Border1 T_Lower_D_Border1 T_Diff_D_Border2 T_Upper_D_Border2 T_Lower_D_Border2 T_Diff_D_Border3 T_Upper_D_Border3 T_Lower_D_Border3 T_Diff_D_Border4 T_Upper_D_Border4 T_Lower_D_Border4 T_Diff_D_Border5 T_Upper_D_Border5 T_Lower_D_Border5 T_Diff_D_Border6 T_Upper_D_Border6 T_Lower_D_Border6 T_Diff_D_Border7 T_Upper_D_Border7 T_Lower_D_Border7 T_Diff_D_Border8 T_Upper_D_Border8 T_Lower_D_Border8 T_Diff_D_Border9 T_Upper_D_Border9 T_Lower_D_Border9 T_Diff_D_Border10 T_Upper_D_Border10 T_Lower_D_Border10 T_Diff_D_Border11 T_Upper_D_Border11 T_Lower_D_Border11 T_Diff_D_Border12 T_Upper_D_Border12 T_Lower_D_Border12 T_Diff_D_Border13 T_Upper_D_Border13 T_Lower_D_Border13 T_Diff_D_Border14 T_Upper_D_Border14 T_Lower_D_Border14 T_Diff_D_Border15 T_Upper_D_Border15 T_Lower_D_Border15 T_Diff_D_Border16 T_Upper_D_Border16 T_Lower_D_Border16 T_Diff_D_Border17 T_Upper_D_Border17 T_Lower_D_Border17 T_Diff_D_Border18 T_Upper_D_Border18 T_Lower_D_Border18 T_Diff_D_Border19 T_Upper_D_Border19 T_Lower_D_Border19

reshape long T_Diff_D_Border T_Upper_D_Border T_Lower_D_Border, i(N) j(band)

twoway (line T_Diff_D_Border band, lcolor(black) lpattern(solid)) ///
	(line T_Upper_D_Border band, lcolor(black) lpattern(tight_dot)) ///
	(line T_Lower_D_Border band, lcolor(black) lpattern(tight_dot)), ///
    ytitle(Difference of Means, size(small)) ylabel(-2(1)2,  angle(horizontal))  ///
    xtitle(Distance from Border (km) ) xtitle(, size(small)) xlabel(, labsize(vsmall))  ///
       legend(off) ///
        title(a. Soil Captation, size(medsmall)) ///
    name("CEC", replace) scheme(s2mono) graphregion(fcolor(white)) 

	
*Precipitaiton
use "Datasets/Geobalance_10kmGrid.dta", clear
foreach var of varlist D_Border20 D_Border21 D_Border22 D_Border23 D_Border24 D_Border25 D_Border26 D_Border27 D_Border28 D_Border29 D_Border30 D_Border31 D_Border32 D_Border33 D_Border34 D_Border35 D_Border36 D_Border37 D_Border38 D_Border39 D_Border40 D_Border41 D_Border42 D_Border43 D_Border44 D_Border45 D_Border46 D_Border47 D_Border48 D_Border49 D_Border50 D_Border1 D_Border2 D_Border3 D_Border4 D_Border5 D_Border6 D_Border7 D_Border8 D_Border9 D_Border10 D_Border11 D_Border12 D_Border13 D_Border14 D_Border15 D_Border16 D_Border17 D_Border18 D_Border19 {
	quietly ttest Prec_Avg if `var' == 1, by(Togo)
	gen T1`var'= r(mu_1)
	gen T2`var'= r(mu_2)
	gen T_SE_`var'= r(se)
} 

foreach var of varlist D_Border20 D_Border21 D_Border22 D_Border23 D_Border24 D_Border25 D_Border26 D_Border27 D_Border28 D_Border29 D_Border30 D_Border31 D_Border32 D_Border33 D_Border34 D_Border35 D_Border36 D_Border37 D_Border38 D_Border39 D_Border40 D_Border41 D_Border42 D_Border43 D_Border44 D_Border45 D_Border46 D_Border47 D_Border48 D_Border49 D_Border50 D_Border1 D_Border2 D_Border3 D_Border4 D_Border5 D_Border6 D_Border7 D_Border8 D_Border9 D_Border10 D_Border11 D_Border12 D_Border13 D_Border14 D_Border15 D_Border16 D_Border17 D_Border18 D_Border19 {
	gen T_Diff_`var' = T2`var'-T1`var'
	gen T_Upper_`var' = T_Diff_`var'+(T_SE_`var'*1.96)
	gen T_Lower_`var' = T_Diff_`var'-(T_SE_`var'*1.96)
} 

gen N = _n
drop if N !=1
keep N T1D_Border20 T2D_Border20 T_SE_D_Border20 T1D_Border21 T2D_Border21 T_SE_D_Border21 T1D_Border22 T2D_Border22 T_SE_D_Border22 T1D_Border23 T2D_Border23 T_SE_D_Border23 T1D_Border24 T2D_Border24 T_SE_D_Border24 T1D_Border25 T2D_Border25 T_SE_D_Border25 T1D_Border26 T2D_Border26 T_SE_D_Border26 T1D_Border27 T2D_Border27 T_SE_D_Border27 T1D_Border28 T2D_Border28 T_SE_D_Border28 T1D_Border29 T2D_Border29 T_SE_D_Border29 T1D_Border30 T2D_Border30 T_SE_D_Border30 T1D_Border31 T2D_Border31 T_SE_D_Border31 T1D_Border32 T2D_Border32 T_SE_D_Border32 T1D_Border33 T2D_Border33 T_SE_D_Border33 T1D_Border34 T2D_Border34 T_SE_D_Border34 T1D_Border35 T2D_Border35 T_SE_D_Border35 T1D_Border36 T2D_Border36 T_SE_D_Border36 T1D_Border37 T2D_Border37 T_SE_D_Border37 T1D_Border38 T2D_Border38 T_SE_D_Border38 T1D_Border39 T2D_Border39 T_SE_D_Border39 T1D_Border40 T2D_Border40 T_SE_D_Border40 T1D_Border41 T2D_Border41 T_SE_D_Border41 T1D_Border42 T2D_Border42 T_SE_D_Border42 T1D_Border43 T2D_Border43 T_SE_D_Border43 T1D_Border44 T2D_Border44 T_SE_D_Border44 T1D_Border45 T2D_Border45 T_SE_D_Border45 T1D_Border46 T2D_Border46 T_SE_D_Border46 T1D_Border47 T2D_Border47 T_SE_D_Border47 T1D_Border48 T2D_Border48 T_SE_D_Border48 T1D_Border49 T2D_Border49 T_SE_D_Border49 T1D_Border50 T2D_Border50 T_SE_D_Border50 T1D_Border1 T2D_Border1 T_SE_D_Border1 T1D_Border2 T2D_Border2 T_SE_D_Border2 T1D_Border3 T2D_Border3 T_SE_D_Border3 T1D_Border4 T2D_Border4 T_SE_D_Border4 T1D_Border5 T2D_Border5 T_SE_D_Border5 T1D_Border6 T2D_Border6 T_SE_D_Border6 T1D_Border7 T2D_Border7 T_SE_D_Border7 T1D_Border8 T2D_Border8 T_SE_D_Border8 T1D_Border9 T2D_Border9 T_SE_D_Border9 T1D_Border10 T2D_Border10 T_SE_D_Border10 T1D_Border11 T2D_Border11 T_SE_D_Border11 T1D_Border12 T2D_Border12 T_SE_D_Border12 T1D_Border13 T2D_Border13 T_SE_D_Border13 T1D_Border14 T2D_Border14 T_SE_D_Border14 T1D_Border15 T2D_Border15 T_SE_D_Border15 T1D_Border16 T2D_Border16 T_SE_D_Border16 T1D_Border17 T2D_Border17 T_SE_D_Border17 T1D_Border18 T2D_Border18 T_SE_D_Border18 T1D_Border19 T2D_Border19 T_SE_D_Border19 T_Diff_D_Border20 T_Upper_D_Border20 T_Lower_D_Border20 T_Diff_D_Border21 T_Upper_D_Border21 T_Lower_D_Border21 T_Diff_D_Border22 T_Upper_D_Border22 T_Lower_D_Border22 T_Diff_D_Border23 T_Upper_D_Border23 T_Lower_D_Border23 T_Diff_D_Border24 T_Upper_D_Border24 T_Lower_D_Border24 T_Diff_D_Border25 T_Upper_D_Border25 T_Lower_D_Border25 T_Diff_D_Border26 T_Upper_D_Border26 T_Lower_D_Border26 T_Diff_D_Border27 T_Upper_D_Border27 T_Lower_D_Border27 T_Diff_D_Border28 T_Upper_D_Border28 T_Lower_D_Border28 T_Diff_D_Border29 T_Upper_D_Border29 T_Lower_D_Border29 T_Diff_D_Border30 T_Upper_D_Border30 T_Lower_D_Border30 T_Diff_D_Border31 T_Upper_D_Border31 T_Lower_D_Border31 T_Diff_D_Border32 T_Upper_D_Border32 T_Lower_D_Border32 T_Diff_D_Border33 T_Upper_D_Border33 T_Lower_D_Border33 T_Diff_D_Border34 T_Upper_D_Border34 T_Lower_D_Border34 T_Diff_D_Border35 T_Upper_D_Border35 T_Lower_D_Border35 T_Diff_D_Border36 T_Upper_D_Border36 T_Lower_D_Border36 T_Diff_D_Border37 T_Upper_D_Border37 T_Lower_D_Border37 T_Diff_D_Border38 T_Upper_D_Border38 T_Lower_D_Border38 T_Diff_D_Border39 T_Upper_D_Border39 T_Lower_D_Border39 T_Diff_D_Border40 T_Upper_D_Border40 T_Lower_D_Border40 T_Diff_D_Border41 T_Upper_D_Border41 T_Lower_D_Border41 T_Diff_D_Border42 T_Upper_D_Border42 T_Lower_D_Border42 T_Diff_D_Border43 T_Upper_D_Border43 T_Lower_D_Border43 T_Diff_D_Border44 T_Upper_D_Border44 T_Lower_D_Border44 T_Diff_D_Border45 T_Upper_D_Border45 T_Lower_D_Border45 T_Diff_D_Border46 T_Upper_D_Border46 T_Lower_D_Border46 T_Diff_D_Border47 T_Upper_D_Border47 T_Lower_D_Border47 T_Diff_D_Border48 T_Upper_D_Border48 T_Lower_D_Border48 T_Diff_D_Border49 T_Upper_D_Border49 T_Lower_D_Border49 T_Diff_D_Border50 T_Upper_D_Border50 T_Lower_D_Border50 T_Diff_D_Border1 T_Upper_D_Border1 T_Lower_D_Border1 T_Diff_D_Border2 T_Upper_D_Border2 T_Lower_D_Border2 T_Diff_D_Border3 T_Upper_D_Border3 T_Lower_D_Border3 T_Diff_D_Border4 T_Upper_D_Border4 T_Lower_D_Border4 T_Diff_D_Border5 T_Upper_D_Border5 T_Lower_D_Border5 T_Diff_D_Border6 T_Upper_D_Border6 T_Lower_D_Border6 T_Diff_D_Border7 T_Upper_D_Border7 T_Lower_D_Border7 T_Diff_D_Border8 T_Upper_D_Border8 T_Lower_D_Border8 T_Diff_D_Border9 T_Upper_D_Border9 T_Lower_D_Border9 T_Diff_D_Border10 T_Upper_D_Border10 T_Lower_D_Border10 T_Diff_D_Border11 T_Upper_D_Border11 T_Lower_D_Border11 T_Diff_D_Border12 T_Upper_D_Border12 T_Lower_D_Border12 T_Diff_D_Border13 T_Upper_D_Border13 T_Lower_D_Border13 T_Diff_D_Border14 T_Upper_D_Border14 T_Lower_D_Border14 T_Diff_D_Border15 T_Upper_D_Border15 T_Lower_D_Border15 T_Diff_D_Border16 T_Upper_D_Border16 T_Lower_D_Border16 T_Diff_D_Border17 T_Upper_D_Border17 T_Lower_D_Border17 T_Diff_D_Border18 T_Upper_D_Border18 T_Lower_D_Border18 T_Diff_D_Border19 T_Upper_D_Border19 T_Lower_D_Border19

reshape long T_Diff_D_Border T_Upper_D_Border T_Lower_D_Border, i(N) j(band)

twoway (line T_Diff_D_Border band, lcolor(black) lpattern(solid)) ///
	(line T_Upper_D_Border band, lcolor(black) lpattern(tight_dot)) ///
	(line T_Lower_D_Border band, lcolor(black) lpattern(tight_dot)), ///
    ytitle(Difference of Means, size(small)) ylabel(-10(5)10,  angle(horizontal))  ///
    xtitle(Distance from Border (km) ) xtitle(, size(small)) xlabel(, labsize(vsmall))  ///
       legend(off) ///
        title(b. Avg Precipitation, size(medsmall)) ///
    name("Prec", replace) scheme(s2mono) graphregion(fcolor(white)) 

	
	
*Elevation
use "Datasets/Geobalance_10kmGrid.dta", clear
foreach var of varlist D_Border20 D_Border21 D_Border22 D_Border23 D_Border24 D_Border25 D_Border26 D_Border27 D_Border28 D_Border29 D_Border30 D_Border31 D_Border32 D_Border33 D_Border34 D_Border35 D_Border36 D_Border37 D_Border38 D_Border39 D_Border40 D_Border41 D_Border42 D_Border43 D_Border44 D_Border45 D_Border46 D_Border47 D_Border48 D_Border49 D_Border50 D_Border1 D_Border2 D_Border3 D_Border4 D_Border5 D_Border6 D_Border7 D_Border8 D_Border9 D_Border10 D_Border11 D_Border12 D_Border13 D_Border14 D_Border15 D_Border16 D_Border17 D_Border18 D_Border19 {
	quietly ttest elev_mean if `var' == 1, by(Togo)
	gen T1`var'= r(mu_1)
	gen T2`var'= r(mu_2)
	gen T_SE_`var'= r(se)
} 

foreach var of varlist D_Border20 D_Border21 D_Border22 D_Border23 D_Border24 D_Border25 D_Border26 D_Border27 D_Border28 D_Border29 D_Border30 D_Border31 D_Border32 D_Border33 D_Border34 D_Border35 D_Border36 D_Border37 D_Border38 D_Border39 D_Border40 D_Border41 D_Border42 D_Border43 D_Border44 D_Border45 D_Border46 D_Border47 D_Border48 D_Border49 D_Border50 D_Border1 D_Border2 D_Border3 D_Border4 D_Border5 D_Border6 D_Border7 D_Border8 D_Border9 D_Border10 D_Border11 D_Border12 D_Border13 D_Border14 D_Border15 D_Border16 D_Border17 D_Border18 D_Border19 {
	gen T_Diff_`var' = T2`var'-T1`var'
	gen T_Upper_`var' = T_Diff_`var'+(T_SE_`var'*1.96)
	gen T_Lower_`var' = T_Diff_`var'-(T_SE_`var'*1.96)
} 

gen N = _n
drop if N !=1
keep N T1D_Border20 T2D_Border20 T_SE_D_Border20 T1D_Border21 T2D_Border21 T_SE_D_Border21 T1D_Border22 T2D_Border22 T_SE_D_Border22 T1D_Border23 T2D_Border23 T_SE_D_Border23 T1D_Border24 T2D_Border24 T_SE_D_Border24 T1D_Border25 T2D_Border25 T_SE_D_Border25 T1D_Border26 T2D_Border26 T_SE_D_Border26 T1D_Border27 T2D_Border27 T_SE_D_Border27 T1D_Border28 T2D_Border28 T_SE_D_Border28 T1D_Border29 T2D_Border29 T_SE_D_Border29 T1D_Border30 T2D_Border30 T_SE_D_Border30 T1D_Border31 T2D_Border31 T_SE_D_Border31 T1D_Border32 T2D_Border32 T_SE_D_Border32 T1D_Border33 T2D_Border33 T_SE_D_Border33 T1D_Border34 T2D_Border34 T_SE_D_Border34 T1D_Border35 T2D_Border35 T_SE_D_Border35 T1D_Border36 T2D_Border36 T_SE_D_Border36 T1D_Border37 T2D_Border37 T_SE_D_Border37 T1D_Border38 T2D_Border38 T_SE_D_Border38 T1D_Border39 T2D_Border39 T_SE_D_Border39 T1D_Border40 T2D_Border40 T_SE_D_Border40 T1D_Border41 T2D_Border41 T_SE_D_Border41 T1D_Border42 T2D_Border42 T_SE_D_Border42 T1D_Border43 T2D_Border43 T_SE_D_Border43 T1D_Border44 T2D_Border44 T_SE_D_Border44 T1D_Border45 T2D_Border45 T_SE_D_Border45 T1D_Border46 T2D_Border46 T_SE_D_Border46 T1D_Border47 T2D_Border47 T_SE_D_Border47 T1D_Border48 T2D_Border48 T_SE_D_Border48 T1D_Border49 T2D_Border49 T_SE_D_Border49 T1D_Border50 T2D_Border50 T_SE_D_Border50 T1D_Border1 T2D_Border1 T_SE_D_Border1 T1D_Border2 T2D_Border2 T_SE_D_Border2 T1D_Border3 T2D_Border3 T_SE_D_Border3 T1D_Border4 T2D_Border4 T_SE_D_Border4 T1D_Border5 T2D_Border5 T_SE_D_Border5 T1D_Border6 T2D_Border6 T_SE_D_Border6 T1D_Border7 T2D_Border7 T_SE_D_Border7 T1D_Border8 T2D_Border8 T_SE_D_Border8 T1D_Border9 T2D_Border9 T_SE_D_Border9 T1D_Border10 T2D_Border10 T_SE_D_Border10 T1D_Border11 T2D_Border11 T_SE_D_Border11 T1D_Border12 T2D_Border12 T_SE_D_Border12 T1D_Border13 T2D_Border13 T_SE_D_Border13 T1D_Border14 T2D_Border14 T_SE_D_Border14 T1D_Border15 T2D_Border15 T_SE_D_Border15 T1D_Border16 T2D_Border16 T_SE_D_Border16 T1D_Border17 T2D_Border17 T_SE_D_Border17 T1D_Border18 T2D_Border18 T_SE_D_Border18 T1D_Border19 T2D_Border19 T_SE_D_Border19 T_Diff_D_Border20 T_Upper_D_Border20 T_Lower_D_Border20 T_Diff_D_Border21 T_Upper_D_Border21 T_Lower_D_Border21 T_Diff_D_Border22 T_Upper_D_Border22 T_Lower_D_Border22 T_Diff_D_Border23 T_Upper_D_Border23 T_Lower_D_Border23 T_Diff_D_Border24 T_Upper_D_Border24 T_Lower_D_Border24 T_Diff_D_Border25 T_Upper_D_Border25 T_Lower_D_Border25 T_Diff_D_Border26 T_Upper_D_Border26 T_Lower_D_Border26 T_Diff_D_Border27 T_Upper_D_Border27 T_Lower_D_Border27 T_Diff_D_Border28 T_Upper_D_Border28 T_Lower_D_Border28 T_Diff_D_Border29 T_Upper_D_Border29 T_Lower_D_Border29 T_Diff_D_Border30 T_Upper_D_Border30 T_Lower_D_Border30 T_Diff_D_Border31 T_Upper_D_Border31 T_Lower_D_Border31 T_Diff_D_Border32 T_Upper_D_Border32 T_Lower_D_Border32 T_Diff_D_Border33 T_Upper_D_Border33 T_Lower_D_Border33 T_Diff_D_Border34 T_Upper_D_Border34 T_Lower_D_Border34 T_Diff_D_Border35 T_Upper_D_Border35 T_Lower_D_Border35 T_Diff_D_Border36 T_Upper_D_Border36 T_Lower_D_Border36 T_Diff_D_Border37 T_Upper_D_Border37 T_Lower_D_Border37 T_Diff_D_Border38 T_Upper_D_Border38 T_Lower_D_Border38 T_Diff_D_Border39 T_Upper_D_Border39 T_Lower_D_Border39 T_Diff_D_Border40 T_Upper_D_Border40 T_Lower_D_Border40 T_Diff_D_Border41 T_Upper_D_Border41 T_Lower_D_Border41 T_Diff_D_Border42 T_Upper_D_Border42 T_Lower_D_Border42 T_Diff_D_Border43 T_Upper_D_Border43 T_Lower_D_Border43 T_Diff_D_Border44 T_Upper_D_Border44 T_Lower_D_Border44 T_Diff_D_Border45 T_Upper_D_Border45 T_Lower_D_Border45 T_Diff_D_Border46 T_Upper_D_Border46 T_Lower_D_Border46 T_Diff_D_Border47 T_Upper_D_Border47 T_Lower_D_Border47 T_Diff_D_Border48 T_Upper_D_Border48 T_Lower_D_Border48 T_Diff_D_Border49 T_Upper_D_Border49 T_Lower_D_Border49 T_Diff_D_Border50 T_Upper_D_Border50 T_Lower_D_Border50 T_Diff_D_Border1 T_Upper_D_Border1 T_Lower_D_Border1 T_Diff_D_Border2 T_Upper_D_Border2 T_Lower_D_Border2 T_Diff_D_Border3 T_Upper_D_Border3 T_Lower_D_Border3 T_Diff_D_Border4 T_Upper_D_Border4 T_Lower_D_Border4 T_Diff_D_Border5 T_Upper_D_Border5 T_Lower_D_Border5 T_Diff_D_Border6 T_Upper_D_Border6 T_Lower_D_Border6 T_Diff_D_Border7 T_Upper_D_Border7 T_Lower_D_Border7 T_Diff_D_Border8 T_Upper_D_Border8 T_Lower_D_Border8 T_Diff_D_Border9 T_Upper_D_Border9 T_Lower_D_Border9 T_Diff_D_Border10 T_Upper_D_Border10 T_Lower_D_Border10 T_Diff_D_Border11 T_Upper_D_Border11 T_Lower_D_Border11 T_Diff_D_Border12 T_Upper_D_Border12 T_Lower_D_Border12 T_Diff_D_Border13 T_Upper_D_Border13 T_Lower_D_Border13 T_Diff_D_Border14 T_Upper_D_Border14 T_Lower_D_Border14 T_Diff_D_Border15 T_Upper_D_Border15 T_Lower_D_Border15 T_Diff_D_Border16 T_Upper_D_Border16 T_Lower_D_Border16 T_Diff_D_Border17 T_Upper_D_Border17 T_Lower_D_Border17 T_Diff_D_Border18 T_Upper_D_Border18 T_Lower_D_Border18 T_Diff_D_Border19 T_Upper_D_Border19 T_Lower_D_Border19

reshape long T_Diff_D_Border T_Upper_D_Border T_Lower_D_Border, i(N) j(band)

twoway (line T_Diff_D_Border band, lcolor(black) lpattern(solid)) ///
	(line T_Upper_D_Border band, lcolor(black) lpattern(tight_dot)) ///
	(line T_Lower_D_Border band, lcolor(black) lpattern(tight_dot)), ///
    ytitle(Difference of Means, size(small)) ylabel(-50(50)150,  angle(horizontal))  ///
    xtitle(Distance from Border (km) ) xtitle(, size(small)) xlabel(, labsize(vsmall))  ///
       legend(off) ///
        title(c. Avg Elevation, size(medsmall)) ///
    name("Elev", replace) scheme(s2mono) graphregion(fcolor(white)) 

	
*D_Kingdom
use "Datasets/Geobalance_10kmGrid.dta", clear
foreach var of varlist D_Border20 D_Border21 D_Border22 D_Border23 D_Border24 D_Border25 D_Border26 D_Border27 D_Border28 D_Border29 D_Border30 D_Border31 D_Border32 D_Border33 D_Border34 D_Border35 D_Border36 D_Border37 D_Border38 D_Border39 D_Border40 D_Border41 D_Border42 D_Border43 D_Border44 D_Border45 D_Border46 D_Border47 D_Border48 D_Border49 D_Border50 D_Border1 D_Border2 D_Border3 D_Border4 D_Border5 D_Border6 D_Border7 D_Border8 D_Border9 D_Border10 D_Border11 D_Border12 D_Border13 D_Border14 D_Border15 D_Border16 D_Border17 D_Border18 D_Border19 {
	quietly ttest d_kingdomkm if `var' == 1, by(Togo)
	gen T1`var'= r(mu_1)
	gen T2`var'= r(mu_2)
	gen T_SE_`var'= r(se)
} 

foreach var of varlist D_Border20 D_Border21 D_Border22 D_Border23 D_Border24 D_Border25 D_Border26 D_Border27 D_Border28 D_Border29 D_Border30 D_Border31 D_Border32 D_Border33 D_Border34 D_Border35 D_Border36 D_Border37 D_Border38 D_Border39 D_Border40 D_Border41 D_Border42 D_Border43 D_Border44 D_Border45 D_Border46 D_Border47 D_Border48 D_Border49 D_Border50 D_Border1 D_Border2 D_Border3 D_Border4 D_Border5 D_Border6 D_Border7 D_Border8 D_Border9 D_Border10 D_Border11 D_Border12 D_Border13 D_Border14 D_Border15 D_Border16 D_Border17 D_Border18 D_Border19 {
	gen T_Diff_`var' = T2`var'-T1`var'
	gen T_Upper_`var' = T_Diff_`var'+(T_SE_`var'*1.96)
	gen T_Lower_`var' = T_Diff_`var'-(T_SE_`var'*1.96)
} 

gen N = _n
drop if N !=1
keep N T1D_Border20 T2D_Border20 T_SE_D_Border20 T1D_Border21 T2D_Border21 T_SE_D_Border21 T1D_Border22 T2D_Border22 T_SE_D_Border22 T1D_Border23 T2D_Border23 T_SE_D_Border23 T1D_Border24 T2D_Border24 T_SE_D_Border24 T1D_Border25 T2D_Border25 T_SE_D_Border25 T1D_Border26 T2D_Border26 T_SE_D_Border26 T1D_Border27 T2D_Border27 T_SE_D_Border27 T1D_Border28 T2D_Border28 T_SE_D_Border28 T1D_Border29 T2D_Border29 T_SE_D_Border29 T1D_Border30 T2D_Border30 T_SE_D_Border30 T1D_Border31 T2D_Border31 T_SE_D_Border31 T1D_Border32 T2D_Border32 T_SE_D_Border32 T1D_Border33 T2D_Border33 T_SE_D_Border33 T1D_Border34 T2D_Border34 T_SE_D_Border34 T1D_Border35 T2D_Border35 T_SE_D_Border35 T1D_Border36 T2D_Border36 T_SE_D_Border36 T1D_Border37 T2D_Border37 T_SE_D_Border37 T1D_Border38 T2D_Border38 T_SE_D_Border38 T1D_Border39 T2D_Border39 T_SE_D_Border39 T1D_Border40 T2D_Border40 T_SE_D_Border40 T1D_Border41 T2D_Border41 T_SE_D_Border41 T1D_Border42 T2D_Border42 T_SE_D_Border42 T1D_Border43 T2D_Border43 T_SE_D_Border43 T1D_Border44 T2D_Border44 T_SE_D_Border44 T1D_Border45 T2D_Border45 T_SE_D_Border45 T1D_Border46 T2D_Border46 T_SE_D_Border46 T1D_Border47 T2D_Border47 T_SE_D_Border47 T1D_Border48 T2D_Border48 T_SE_D_Border48 T1D_Border49 T2D_Border49 T_SE_D_Border49 T1D_Border50 T2D_Border50 T_SE_D_Border50 T1D_Border1 T2D_Border1 T_SE_D_Border1 T1D_Border2 T2D_Border2 T_SE_D_Border2 T1D_Border3 T2D_Border3 T_SE_D_Border3 T1D_Border4 T2D_Border4 T_SE_D_Border4 T1D_Border5 T2D_Border5 T_SE_D_Border5 T1D_Border6 T2D_Border6 T_SE_D_Border6 T1D_Border7 T2D_Border7 T_SE_D_Border7 T1D_Border8 T2D_Border8 T_SE_D_Border8 T1D_Border9 T2D_Border9 T_SE_D_Border9 T1D_Border10 T2D_Border10 T_SE_D_Border10 T1D_Border11 T2D_Border11 T_SE_D_Border11 T1D_Border12 T2D_Border12 T_SE_D_Border12 T1D_Border13 T2D_Border13 T_SE_D_Border13 T1D_Border14 T2D_Border14 T_SE_D_Border14 T1D_Border15 T2D_Border15 T_SE_D_Border15 T1D_Border16 T2D_Border16 T_SE_D_Border16 T1D_Border17 T2D_Border17 T_SE_D_Border17 T1D_Border18 T2D_Border18 T_SE_D_Border18 T1D_Border19 T2D_Border19 T_SE_D_Border19 T_Diff_D_Border20 T_Upper_D_Border20 T_Lower_D_Border20 T_Diff_D_Border21 T_Upper_D_Border21 T_Lower_D_Border21 T_Diff_D_Border22 T_Upper_D_Border22 T_Lower_D_Border22 T_Diff_D_Border23 T_Upper_D_Border23 T_Lower_D_Border23 T_Diff_D_Border24 T_Upper_D_Border24 T_Lower_D_Border24 T_Diff_D_Border25 T_Upper_D_Border25 T_Lower_D_Border25 T_Diff_D_Border26 T_Upper_D_Border26 T_Lower_D_Border26 T_Diff_D_Border27 T_Upper_D_Border27 T_Lower_D_Border27 T_Diff_D_Border28 T_Upper_D_Border28 T_Lower_D_Border28 T_Diff_D_Border29 T_Upper_D_Border29 T_Lower_D_Border29 T_Diff_D_Border30 T_Upper_D_Border30 T_Lower_D_Border30 T_Diff_D_Border31 T_Upper_D_Border31 T_Lower_D_Border31 T_Diff_D_Border32 T_Upper_D_Border32 T_Lower_D_Border32 T_Diff_D_Border33 T_Upper_D_Border33 T_Lower_D_Border33 T_Diff_D_Border34 T_Upper_D_Border34 T_Lower_D_Border34 T_Diff_D_Border35 T_Upper_D_Border35 T_Lower_D_Border35 T_Diff_D_Border36 T_Upper_D_Border36 T_Lower_D_Border36 T_Diff_D_Border37 T_Upper_D_Border37 T_Lower_D_Border37 T_Diff_D_Border38 T_Upper_D_Border38 T_Lower_D_Border38 T_Diff_D_Border39 T_Upper_D_Border39 T_Lower_D_Border39 T_Diff_D_Border40 T_Upper_D_Border40 T_Lower_D_Border40 T_Diff_D_Border41 T_Upper_D_Border41 T_Lower_D_Border41 T_Diff_D_Border42 T_Upper_D_Border42 T_Lower_D_Border42 T_Diff_D_Border43 T_Upper_D_Border43 T_Lower_D_Border43 T_Diff_D_Border44 T_Upper_D_Border44 T_Lower_D_Border44 T_Diff_D_Border45 T_Upper_D_Border45 T_Lower_D_Border45 T_Diff_D_Border46 T_Upper_D_Border46 T_Lower_D_Border46 T_Diff_D_Border47 T_Upper_D_Border47 T_Lower_D_Border47 T_Diff_D_Border48 T_Upper_D_Border48 T_Lower_D_Border48 T_Diff_D_Border49 T_Upper_D_Border49 T_Lower_D_Border49 T_Diff_D_Border50 T_Upper_D_Border50 T_Lower_D_Border50 T_Diff_D_Border1 T_Upper_D_Border1 T_Lower_D_Border1 T_Diff_D_Border2 T_Upper_D_Border2 T_Lower_D_Border2 T_Diff_D_Border3 T_Upper_D_Border3 T_Lower_D_Border3 T_Diff_D_Border4 T_Upper_D_Border4 T_Lower_D_Border4 T_Diff_D_Border5 T_Upper_D_Border5 T_Lower_D_Border5 T_Diff_D_Border6 T_Upper_D_Border6 T_Lower_D_Border6 T_Diff_D_Border7 T_Upper_D_Border7 T_Lower_D_Border7 T_Diff_D_Border8 T_Upper_D_Border8 T_Lower_D_Border8 T_Diff_D_Border9 T_Upper_D_Border9 T_Lower_D_Border9 T_Diff_D_Border10 T_Upper_D_Border10 T_Lower_D_Border10 T_Diff_D_Border11 T_Upper_D_Border11 T_Lower_D_Border11 T_Diff_D_Border12 T_Upper_D_Border12 T_Lower_D_Border12 T_Diff_D_Border13 T_Upper_D_Border13 T_Lower_D_Border13 T_Diff_D_Border14 T_Upper_D_Border14 T_Lower_D_Border14 T_Diff_D_Border15 T_Upper_D_Border15 T_Lower_D_Border15 T_Diff_D_Border16 T_Upper_D_Border16 T_Lower_D_Border16 T_Diff_D_Border17 T_Upper_D_Border17 T_Lower_D_Border17 T_Diff_D_Border18 T_Upper_D_Border18 T_Lower_D_Border18 T_Diff_D_Border19 T_Upper_D_Border19 T_Lower_D_Border19

reshape long T_Diff_D_Border T_Upper_D_Border T_Lower_D_Border, i(N) j(band)

twoway (line T_Diff_D_Border band, lcolor(black) lpattern(solid)) ///
	(line T_Upper_D_Border band, lcolor(black) lpattern(tight_dot)) ///
	(line T_Lower_D_Border band, lcolor(black) lpattern(tight_dot)), ///
    ytitle(Difference of Means, size(small)) ylabel(-25(25)25,  angle(horizontal))  ///
    xtitle(Distance from Border (km) ) xtitle(, size(small)) xlabel(, labsize(vsmall))  ///
       legend(off) ///
       title(d. D Precolonial Kingdom (km), size(medsmall)) ///
    name("kingdom", replace) scheme(s2mono) graphregion(fcolor(white)) 

	
graph combine CEC Prec Elev kingdom, ///
 row(2) title("Figure G1: Balance of Pretreatment Attributes for Entire Border")
}

****** FIGURE G2: Balance of Geographic Attributes between Sample Sites
{
cd "~/Letsa_Wilfahrt_CPS_Replication Files/"

use "Datasets/Original_Survey.dta", clear

reg elev_mean Togo
	est sto elev

reg cec_mean Togo
	est sto cec

reg d_Kingdom_samplesitekm Togo
	est sto kingdom

reg Prec_Avg Togo
	est sto Prec_Avg

coefplot cec Prec_Avg elev kingdom , keep(Togo) vertical levels(95) ///
	yline(0, lcolor(gs12) lwidth(thin)) msymbol(square_hollow) mcolor(black) ciopts(lcolor(black black)) ///
	ytitle(Coefficient for Togo)  ///
	xlabel(.7 "Soil Captation" .9 "Avg Precip" 1.1 "Avg Elev" 1.3 "D Kingdom", labsize(small)) ///
	title("", size(medsmall)) legend(off) scheme(s1mono)
}

****** FIGURE G3: Comparative Democratic Trends Over Time (VDem Data)
{
* link to downloaded vdem data here (V-Dem-CY-Core): https://www.v-dem.net/data/the-v-dem-dataset/country-year-v-dem-core/

keep if country_name == "Ghana" | country_name == "Togo" 

keep year country_name v2x_egaldem v2x_polyarchy v2x_libdem v2x_partipdem v2x_delibdem

*Ghana Togo
twoway (line v2x_polyarchy year if country_name == "Ghana"  & year > 1959 & year < 2019, lcolor(black) lpattern(solid)) ///
	(line v2x_polyarchy year if country_name == "Togo"  & year > 1959 & year < 2019, lcolor(gs9) lpattern(solid)), ///
	ylabel(0(.2)1) ytitle("") xtitle("") title(a. Electoral Democracy Index) legend(off)  name("Polyarchy", replace)

twoway (line v2x_libdem year if country_name == "Ghana"  & year > 1959 & year < 2019, lcolor(black) lpattern(solid)) ///
	(line v2x_libdem year if country_name == "Togo"  & year > 1959 & year < 2019, lcolor(gs9) lpattern(solid)), ///
	ylabel(0(.2)1) ytitle("") xtitle("") title(b. Liberal Democracy Index) legend(off)  name("LibDem", replace)

twoway (line v2x_delibdem year if country_name == "Ghana"  & year > 1959 & year < 2019, lcolor(black) lpattern(solid)) ///
	(line v2x_delibdem year if country_name == "Togo"  & year > 1959 & year < 2019, lcolor(gs9) lpattern(solid)), ///
	ylabel(0(.2)1) ytitle("")  xtitle("") title(c. Deliberative Democracy Index) legend(off)  name("DelibDem", replace)

twoway (line v2x_partipdem year if country_name == "Ghana"  & year > 1959 & year < 2019, lcolor(black) lpattern(solid)) ///
	(line v2x_partipdem year if country_name == "Togo"  & year > 1959 & year < 2019, lcolor(gs9) lpattern(solid)), ///
	ylabel(0(.2)1) ytitle("")  xtitle("") title(d. Participative Democracy Index) legend(off)  name("ParticDem", replace)

twoway (line v2x_egaldem year if country_name == "Ghana"  & year > 1959 & year < 2019, lcolor(black) lpattern(solid)) ///
	(line v2x_egaldem year if country_name == "Togo"  & year > 1959 & year < 2019, lcolor(gs9) lpattern(solid)), ///
	ylabel(0(.2)1) ytitle("")  xtitle("") title(e. Egalitarian Democracy Index) legend(order(1 "Ghana" 2 "Togo") position(6) rows(1))  name("EgalDem", replace)

graph combine Polyarchy LibDem DelibDem ParticDem EgalDem, ///
 col(2) 
}
 
****** TABLE G1: Model Results for Figure 3 – Full results excluding migrants
{
use "Datasets/Original_Survey_Migrants.dta", clear
*note data file generated in Figures_MainText

revrs Q83
rename revQ83 Coll_Eff1
rename Q84 Coll_Eff2
rename CollectiveEfficacy_Factor2 Coll_Eff3

reshape long Coll_Eff, i(InstanceID) j(item)

tab item, gen(i)
rename i3 self1

for var Age   Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex: gen s_X1 = self1*X

gen vign1 = 1-self1
eq het: vign1 self1

constraint def 1 [lns1]self1=0

eq thresh: Age  Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex

gllamm Coll_Eff s_Togo1 s_Age1  s_Education21 s_HH_SES1  s_IndEfficacy_Factor1 s_Ethnic_Minority1 s_H6bpopulationest1 s_InfrastructureIndex1 i1 i2 if Nationality_Other == 0 , robust/*
*/ i(InstanceID) link(soprobit) s(het) ethresh(thresh) constr(1) /*
*/ init

est sto Vignette_SelfMigrate
 estadd local  C  "Yes"

* 2 Gen (parents)
use "Datasets/Original_Survey_Migrants.dta", clear
 
 revrs Q83
rename revQ83 Coll_Eff1
rename Q84 Coll_Eff2
rename CollectiveEfficacy_Factor2 Coll_Eff3

reshape long Coll_Eff, i(InstanceID) j(item)

tab item, gen(i)
rename i3 self1

for var Age   Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex: gen s_X1 = self1*X

gen vign1 = 1-self1
eq het: vign1 self1

constraint def 1 [lns1]self1=0

eq thresh: Age  Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex

gllamm Coll_Eff s_Togo1 s_Age1  s_Education21 s_HH_SES1  s_IndEfficacy_Factor1 s_Ethnic_Minority1 s_H6bpopulationest1 s_InfrastructureIndex1 i1 i2 if Migrant_2Gen == 0 , robust/*
*/ i(InstanceID) link(soprobit) s(het) ethresh(thresh) constr(1) /*
*/ init

est sto Vignette_2gen
 estadd local  C  "Yes"


* 3 Gen (parents, respondent)
use "Datasets/Original_Survey_Migrants.dta", clear

revrs Q83
rename revQ83 Coll_Eff1
rename Q84 Coll_Eff2
rename CollectiveEfficacy_Factor2 Coll_Eff3

reshape long Coll_Eff, i(InstanceID) j(item)

tab item, gen(i)
rename i3 self1

for var Age   Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex: gen s_X1 = self1*X

gen vign1 = 1-self1
eq het: vign1 self1

constraint def 1 [lns1]self1=0

eq thresh: Age  Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex

gllamm Coll_Eff s_Togo1 s_Age1  s_Education21 s_HH_SES1  s_IndEfficacy_Factor1 s_Ethnic_Minority1 s_H6bpopulationest1 s_InfrastructureIndex1 i1 i2 if Migrant_3Gen == 0 , robust/*
*/ i(InstanceID) link(soprobit) s(het) ethresh(thresh) constr(1) /*
*/ init

est sto Vignette_3gen
 estadd local  C  "Yes"


* ALL MIGRANT HISTORY + VILLAGE THAT MOVED
use "Datasets/Original_Survey_Migrants.dta", clear

revrs Q83
rename revQ83 Coll_Eff1
rename Q84 Coll_Eff2
rename CollectiveEfficacy_Factor2 Coll_Eff3

reshape long Coll_Eff, i(InstanceID) j(item)

tab item, gen(i)
rename i3 self1

for var Age   Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex: gen s_X1 = self1*X

gen vign1 = 1-self1
eq het: vign1 self1

constraint def 1 [lns1]self1=0

eq thresh: Age  Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex

gllamm Coll_Eff s_Togo1 s_Age1  s_Education21 s_HH_SES1  s_IndEfficacy_Factor1 s_Ethnic_Minority1 s_H6bpopulationest1 s_InfrastructureIndex1 i1 i2 if AllMigrants == 0 , robust/*
*/ i(InstanceID) link(soprobit) s(het) ethresh(thresh) constr(1) /*
*/ init

est sto Vignette_AllMigrants
 estadd local  C  "Yes"

esttab Vignette_SelfMigrate Vignette_2gen Vignette_3gen Vignette_AllMigrants  using "Tables Output/TableG1.tex", replace /// 
	scalars("C Controls") wide se b(2) star(** 0.05 *** 0.001) ///
	keep(s_Togo1) ///
	title("TABLE G1: Model Results for Figure 3 – Full results excluding migrants")
}

****** FIGURE G4: Contrasts of Predictive Margins of Cohort Effect (with 95% CIs)
{
use "Datasets/Original_Survey.dta", clear

gen Year = 2019 if Togo == 0
replace Year = 2021 if Togo == 1
replace Year = 2019 if Togo == 1 & SHELL_AGE == .

gen YearBorn = Year-Age
gen Year18 = YearBorn+18

gen Cohort = .
replace Cohort = 1 if Year18 < 1960 
replace Cohort = 2 if Year18 > 1959 & Year18 < 1965
replace Cohort = 3 if Year18 > 1964 & Year18 < 1970
replace Cohort = 4 if Year18 > 1969 & Year18 < 1975
replace Cohort = 5 if Year18 > 1974 & Year18 < 1980
replace Cohort = 6 if Year18 > 1979 & Year18 < 1985
replace Cohort = 7 if Year18 > 1984 & Year18 < 1990
replace Cohort = 8 if Year18 > 1989 & Year18 < 1995
replace Cohort = 9 if Year18 > 1994 & Year18 < 2000
replace Cohort = 10 if Year18 > 1999 & Year18 < 2005
replace Cohort = 11 if Year18 > 2004 & Year18 < 2010
replace Cohort = 12 if Year18 > 2009 & Year18 < 2015
replace Cohort = 13 if Year18 > 2015 

label define Cohort 1 "1920s-50s" 2 "1960-64" 3 "1965-69" 4 "1970-74" 5 "1975-79" 6 "1880-84" 7 "1985-89" 8 "1990-94" 9 "1995-99" 10 "2000-4" 11 "2005-9" 12 "2010-14" 13 "2015-" , replace
label values Cohort Cohort

xtmixed CollectiveEfficacy_Factor2 i.Togo##Cohort Age  Education2 HH_SES Yrs_in_Village IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex || Village:, robust cluster(Village)
margins Togo, at(Cohort = (1(1)13)) 
marginsplot, recast(line) recastci(rarea) ///
    plot1opts(lcolor(navy) lwidth(medium)) /// 
    ci1opts(color(navy%30)) /// /
    plot2opts(lcolor(orange_red)) /// 
    ci2opts(color(orange_red%10)) /// 
	xtitle("Period Turned 18") xlabel(, angle(45)) legend(order(3 "Ghana" 4 "Togo")) ///
	title("Figure G4: Contrasts of Predictive Margins of Cohort Effect (with 95% CIs)")
}

****** TABLE G2: Figure 4 Model Results; Cohort Effects
{
use "Datasets/Original_Survey.dta", clear

gen Year = 2019 if Togo == 0
replace Year = 2021 if Togo == 1
replace Year = 2019 if Togo == 1 & SHELL_AGE == .

gen YearBorn = Year-Age
gen Year18 = YearBorn+18

gen Cohort = .
replace Cohort = 1 if Year18 < 1960 
replace Cohort = 2 if Year18 > 1959 & Year18 < 1965
replace Cohort = 3 if Year18 > 1964 & Year18 < 1970
replace Cohort = 4 if Year18 > 1969 & Year18 < 1975
replace Cohort = 5 if Year18 > 1974 & Year18 < 1980
replace Cohort = 6 if Year18 > 1979 & Year18 < 1985
replace Cohort = 7 if Year18 > 1984 & Year18 < 1990
replace Cohort = 8 if Year18 > 1989 & Year18 < 1995
replace Cohort = 9 if Year18 > 1994 & Year18 < 2000
replace Cohort = 10 if Year18 > 1999 & Year18 < 2005
replace Cohort = 11 if Year18 > 2004 & Year18 < 2010
replace Cohort = 12 if Year18 > 2009 & Year18 < 2015
replace Cohort = 13 if Year18 > 2015 

label define Cohort 1 "1920s-50s" 2 "1960-64" 3 "1965-69" 4 "1970-74" 5 "1975-79" 6 "1880-84" 7 "1985-89" 8 "1990-94" 9 "1995-99" 10 "2000-4" 11 "2005-9" 12 "2010-14" 13 "2015-" , replace
label values Cohort Cohort

xtmixed CollectiveEfficacy_Factor2 i.Togo##Cohort Age  Education2 HH_SES Yrs_in_Village IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex || Village:, robust cluster(Village)
est sto C_Cohort
 estadd local  C  "Yes"
 estadd local  P  "Yes"

esttab C_Cohort  using "Tables Output/TableG2.tex", replace /// ///
	scalars("P Period Dummies" "C Controls") wide se b(3) star(** 0.05 *** 0.001) ///
   	drop(Age  Education2 HH_SES Yrs_in_Village IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex) ///
   title("TABLE G2: Figure 4 Model Results; Cohort Effects")
}

****** TABLE G3: Table 2 Replication; Turning 18 After Ghana’s Democratization
{
use "Datasets/Original_Survey.dta", clear

revrs Q83
rename revQ83 Coll_Eff1
rename Q84 Coll_Eff2
rename CollectiveEfficacy_Factor2 Coll_Eff3

gen Year = 2019 if Togo == 0
replace Year = 2021 if Togo == 1
replace Year = 2019 if Togo == 1 & SHELL_AGE == .

gen YearBorn = Year-Age
gen Year18 = YearBorn+18

gen post1992 = 0
replace post1992 = 1 if Year18 > 1992

gen Togo_post1992 = Togo*post1992

reshape long Coll_Eff, i(InstanceID) j(item)

tab item, gen(i)
rename i3 self1

for var Age  Togo_post1992 Togo post1992 Education2  HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex: gen s_X1 = self1*X

gen vign1 = 1-self1
eq het: vign1 self1

constraint def 1 [lns1]self1=0

eq thresh: Age  Education2 Togo_post1992 Togo post1992 HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex

gllamm Coll_Eff s_Togo1 s_Togo_post19921  s_post19921 s_Age1  s_Education21 s_HH_SES1  s_IndEfficacy_Factor1 s_Ethnic_Minority1 s_H6bpopulationest1 s_InfrastructureIndex1 i1 i2 , robust/*
*/ i(InstanceID) link(soprobit) s(het) ethresh(thresh) constr(1) /*
*/ init

est sto C_Togo18
 estadd local  C  "Yes"

esttab C_Togo18  using "Tables Output/TableG3.tex", replace /// ///
	scalars("C Controls") wide se b(3) star(** 0.05 *** 0.001) ///
	keep(s_Togo1 s_Togo_post19921 s_post19921) ///
 	order(s_Togo1 s_Togo_post19921 s_post19921) ///
   title("TABLE G3: Table 2 Replication; Turning 18 After Ghana’s Democratization")
}

****** FIGURE G5: Nature of problem with public resources encountered in village in previous year
{
use "Datasets/Original_Survey.dta", clear

label define Q25BiggestProblem 1 "School" 2 "Water Infrastructure" 3 "Clinic" 4 "Roads" 5 "Electricity" 6 "Latrines" 7 "Other"  
gen Q25BiggestProblem = .
replace Q25BiggestProblem = 1 if Q25Prob1 == 1
replace Q25BiggestProblem = 2 if Q25Prob1 == 3
replace Q25BiggestProblem = 3 if Q25Prob1 == 4
replace Q25BiggestProblem = 4 if Q25Prob1 == 5
replace Q25BiggestProblem = 5 if Q25Prob1 == 7
replace Q25BiggestProblem = 6 if Q25Prob1 == 6
replace Q25BiggestProblem = 7 if Q25Prob1 == 2
label values Q25BiggestProblem Q25BiggestProblem

histogram Q25BiggestProblem, percent barwidth(.9) xlabel(1 "School" 2 "Water Infrastructure" 3 "Clinic" 4 "Roads" 5 "Electricity" 6 "Latrines" 7 "Other" , angle(forty_five)) ///
	by(Togo) ytitle("%")  col(1)  xtitle("") ///
	by(, note("") legend(off) title("Figure G5: Nature of problem with public resources encountered in village in previous year"))
}	

****** TABLE G4: Model Results for Anchoring Vignettes; Social Capital Tests
{
use "Datasets/Original_Survey.dta", clear

revrs Q83
rename revQ83 Coll_Eff1
rename Q84 Coll_Eff2
rename CollectiveEfficacy_Factor2 Coll_Eff3

reshape long Coll_Eff, i(InstanceID) j(item)

tab item, gen(i)
rename i3 self1

for var Age GroupMmbr TrustNeighbors Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex: gen s_X1 = self1*X

gen vign1 = 1-self1
eq het: vign1 self1

constraint def 1 [lns1]self1=0

eq thresh: Age GroupMmbr Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex

gllamm Coll_Eff s_Togo1 s_GroupMmbr1 s_Age1  s_Education21 s_HH_SES1  s_IndEfficacy_Factor1 s_Ethnic_Minority1 s_H6bpopulationest1 s_InfrastructureIndex1 i1 i2 , robust/*
*/ i(InstanceID) link(soprobit) s(het) ethresh(thresh) constr(1) /*
*/ init

est sto C_GrpMmbr
 estadd local  C  "Yes"
 
eq thresh: Age TrustNeighbors Education2 Togo HH_SES  IndEfficacy_Factor Ethnic_Minority H6bpopulationest InfrastructureIndex

gllamm Coll_Eff s_Togo1 s_TrustNeighbors1 s_Age1  s_Education21 s_HH_SES1  s_IndEfficacy_Factor1 s_Ethnic_Minority1 s_H6bpopulationest1 s_InfrastructureIndex1 i1 i2 , robust/*
*/ i(InstanceID) link(soprobit) s(het) ethresh(thresh) constr(1) /*
*/ init

est sto C_Neighbors
 estadd local  C  "Yes"

esttab C_GrpMmbr C_Neighbors  using "Tables Output/TableG4.tex", replace /// ///
	scalars("C Controls") wide se b(2) star(** 0.05 *** 0.001) ///
	keep(s_Togo1 s_GroupMmbr1 s_TrustNeighbors1) ///
 	order(s_Togo1 s_GroupMmbr1 s_TrustNeighbors1) ///
   title("TABLE G4: Model Results for Anchoring Vignettes; Social Capital Tests")
}

****** Figure H1: Comparative Democratic Trends Over Time – Nigeria & Benin (VDem Data)
{
* link to downloaded vdem data here (V-Dem-CY-Core): https://www.v-dem.net/data/the-v-dem-dataset/country-year-v-dem-core/

keep if country_name == "Benin" | country_name == "Nigeria"

twoway (line v2x_polyarchy year if country_name == "Nigeria"  & year > 1959 & year < 2019, lcolor(black) lpattern(solid)) ///
	(line v2x_polyarchy year if country_name == "Benin"  & year > 1959 & year < 2019, lcolor(gs9) lpattern(solid)), ///
	ylabel(0(.2)1) ytitle("")  xtitle("") title(a. Electoral Democracy Index) legend(off)  name("Polyarchy", replace)

twoway (line v2x_libdem year if country_name == "Nigeria"  & year > 1959 & year < 2019, lcolor(black) lpattern(solid)) ///
	(line v2x_libdem year if country_name == "Benin"  & year > 1959 & year < 2019, lcolor(gs9) lpattern(solid)), ///
	ylabel(0(.2)1) ytitle("")  xtitle("") title(b. Liberal Democracy Index) legend(off)  name("LibDem", replace)

twoway (line v2x_delibdem year if country_name == "Nigeria"  & year > 1959 & year < 2019, lcolor(black) lpattern(solid)) ///
	(line v2x_delibdem year if country_name == "Benin"  & year > 1959 & year < 2019, lcolor(gs9) lpattern(solid)), ///
	ylabel(0(.2)1) ytitle("")  xtitle("") title(c. Deliberative Democracy Index) legend(off)  name("DelibDem", replace)

twoway (line v2x_partipdem year if country_name == "Nigeria"  & year > 1959 & year < 2019, lcolor(black) lpattern(solid)) ///
	(line v2x_partipdem year if country_name == "Benin"  & year > 1959 & year < 2019, lcolor(gs9) lpattern(solid)), ///
	ylabel(0(.2)1) ytitle("")  xtitle("") title(d. Participative Democracy Index) legend(off)  name("ParticDem", replace)

twoway (line v2x_egaldem year if country_name == "Nigeria"  & year > 1959 & year < 2019, lcolor(black) lpattern(solid)) ///
	(line v2x_egaldem year if country_name == "Benin"  & year > 1959 & year < 2019, lcolor(gs9) lpattern(solid)), ///
	ylabel(0(.2)1) ytitle("")  xtitle("") title(e. Egalitarian Democracy Index) legend(order(1 "Nigeria" 2 "Benin") position(6) rows(1))  name("EgalDem", replace)

graph combine Polyarchy LibDem DelibDem ParticDem EgalDem, ///
 col(2) 
}

****** TABLE H1: Model Results of Figure 5: Village Problems & Problem-Solving, Benin-Nigeria Border Sample
{
use "Datasets/WB_LSMS_Benin_NGA_Final.dta", clear

label var N_Problems "# Problems"
label var Perc_ProblemRaisedbyComm "% Raised Community"
label var Perc_ProblemRaisedbyChief "% Raised Chief"
label var Perc_ProblemRaisedbyCS "% Raised Civil Soc"
label var Perc_ProblemRaisedbyState "% Raised State"
label var Perc_Problems_Discussed "% Discussed"
label var Perc_Problems_Project "% Problems Projects"
label var Perc_CommMaindOeuvre "% Donate Labor"
label var Perc_CommDons "% Donate Money"
label var Perc_CommMaterial "% Donate Materials"
label var Perc_Community_Contributions "% Any Donate"

collapse (first) Admin1 Benin Country (min) d_border_km (mean)  cashcrop Max_CashCrop  Perc_ProblemRaisedbyState Perc_ProblemRaisedbyCS Perc_ProblemRaisedbyChief Perc_ProblemRaisedbyComm N_Problems services Route groupments ELF Perc_Problems_Discussed Perc_Problems_Project Perc_CommMaindOeuvre Perc_CommDons Perc_CommMaterial Perc_Community_Contributions, by(Final_EA)

drop if d_border_km > 101

reg N_Problems Benin  if Max_CashCrop < 6, cluster(Admin1) robust
	est store NProb
	estadd local  C  "Yes"
reg N_Problems Benin services Route groupments ELF  if Max_CashCrop < 6, cluster(Admin1) robust
	est store NProb2
	estadd local  C  "Yes"

reg Perc_ProblemRaisedbyComm Benin if Max_CashCrop < 6, cluster(Admin1) robust
	est store Comm
	estadd local  C  "Yes"
reg Perc_ProblemRaisedbyComm Benin services Route groupments ELF  N_Problems if Max_CashCrop < 6, cluster(Admin1) robust
	est store Comm2
	estadd local  C  "Yes"

reg Perc_ProblemRaisedbyChief Benin  if Max_CashCrop < 6, cluster(Admin1) robust
	est store Chief
	estadd local  C  "Yes"
reg Perc_ProblemRaisedbyChief Benin services Route groupments ELF  N_Problems if Max_CashCrop < 6, cluster(Admin1) robust
	est store Chief2
	estadd local  C  "Yes"

reg Perc_ProblemRaisedbyCS Benin  if Max_CashCrop < 6, cluster(Admin1) robust
	est store CS
	estadd local  C  "Yes"
reg Perc_ProblemRaisedbyCS Benin services Route groupments ELF  N_Problems if Max_CashCrop < 6, cluster(Admin1) robust
	est store CS2
	estadd local  C  "Yes"

esttab NProb NProb2 Comm Comm2 Chief Chief2 CS CS2 using "Tables Output/TableH1a.tex", replace /// ///
	scalars(r2 "C Controls") wide se b(2) star(** 0.05 *** 0.001) ///
	keep(Benin) ///
   title("TABLE H1a: Model Results of Figure 5: Village Problems & Problem-Solving, Benin-Nigeria Border Sample")

reg Perc_ProblemRaisedbyState Benin  if Max_CashCrop < 6, cluster(Admin1) robust
	est store State
	estadd local  C  "Yes"
reg Perc_ProblemRaisedbyState Benin services Route groupments ELF  N_Problems if Max_CashCrop < 6, cluster(Admin1) robust
	est store State2
	estadd local  C  "Yes"

reg Perc_Problems_Discussed Benin  if Max_CashCrop < 6, cluster(Admin1) robust
	est store Discuss
	estadd local  C  "Yes"
reg Perc_Problems_Discussed Benin services Route  groupments ELF  N_Problems if Max_CashCrop < 6, cluster(Admin1) robust
	est store Discuss2
	estadd local  C  "Yes"

reg Perc_Problems_Project Benin if Max_CashCrop < 6, cluster(Admin1) robust
	est store Project
	estadd local  C  "Yes"
reg Perc_Problems_Project Benin services Route  groupments ELF  N_Problems if Max_CashCrop < 6, cluster(Admin1) robust
	est store Project2
	estadd local  C  "Yes"

reg Perc_CommMaindOeuvre Benin if Max_CashCrop < 6, cluster(Admin1) robust
	est store CommMain
	estadd local  C  "Yes"
reg Perc_CommMaindOeuvre Benin services Route  groupments ELF  N_Problems if Max_CashCrop < 6, cluster(Admin1) robust
	est store CommMain2
	estadd local  C  "Yes"

esttab State State2 Discuss Discuss2 Project Project2 CommMain CommMain2 using "Tables Output/TableH1b.tex", replace /// ///
	scalars(r2 "C Controls") wide se b(2) star(** 0.05 *** 0.001) ///
	keep(Benin) ///
   title("TABLE H1b: Model Results of Figure 5: Village Problems & Problem-Solving, Benin-Nigeria Border Sample")

 
reg Perc_CommDons Benin  if Max_CashCrop < 6, cluster(Admin1) robust
	est store CommDons
	estadd local  C  "Yes"
reg Perc_CommDons Benin services Route  groupments ELF  N_Problems if Max_CashCrop < 6, cluster(Admin1) robust
	est store CommDons2
	estadd local  C  "Yes"

reg Perc_CommMaterial Benin  if Max_CashCrop < 6, cluster(Admin1) robust
	est store CommMaterial
	estadd local  C  "Yes"
reg Perc_CommMaterial Benin services Route  groupments ELF  N_Problems if Max_CashCrop < 6, cluster(Admin1) robust
	est store CommMaterial2
	estadd local  C  "Yes"

reg Perc_Community_Contributions Benin if Max_CashCrop < 6, cluster(Admin1) robust
	est store CommContr
	estadd local  C  "Yes"
reg Perc_Community_Contributions Benin services Route  groupments ELF  N_Problems if Max_CashCrop < 6, cluster(Admin1) robust
	est store CommContr2
	estadd local  C  "Yes"

esttab CommDons CommDons2 CommMaterial CommMaterial2 CommContr CommContr2 using "Tables Output/TableH1c.tex", replace /// ///
	scalars(r2 "C Controls") wide se b(2) star(** 0.05 *** 0.001) ///
	keep(Benin) ///
   title("TABLE H1c: Model Results of Figure 5: Village Problems & Problem-Solving, Benin-Nigeria Border Sample")
}

****** TABLE H2: Village Problems & Problem-Solving, Full World Bank LSMS Sample
{
use "Datasets/WB_LSMS_Full_Final.dta", clear

mixed N_Problems  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store NProb
	estadd local  C  "Yes"
mixed N_Problems  FormerFrench  services Route if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store NProb2
	estadd local  C  "Yes"

mixed Perc_ProblemRaisedbyComm  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store Comm
	estadd local  C  "Yes"
mixed Perc_ProblemRaisedbyComm FormerFrench  services Route N_Problems  if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store Comm2
	estadd local  C  "Yes"

mixed Perc_ProblemRaisedbyChief  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store Chief
	estadd local  C  "Yes"
mixed Perc_ProblemRaisedbyChief FormerFrench  services Route N_Problems  if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store Chief2
	estadd local  C  "Yes"

mixed Perc_ProblemRaisedbyCS  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store CS
	estadd local  C  "Yes"
mixed Perc_ProblemRaisedbyCS FormerFrench  services Route N_Problems  if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store CS2
	estadd local  C  "Yes"

esttab NProb NProb2  Comm Comm2 Chief Chief2 CS CS2 using "Tables Output/TableH2a.tex", replace /// ///
	scalars("C Controls") wide se b(2) star(** 0.05 *** 0.001) ///
	keep(FormerFrench) ///
   title("TABLE H2a: Village Problems & Problem-Solving, Full World Bank LSMS Sample")


mixed Perc_ProblemRaisedbyState  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store State
	estadd local  C  "Yes"
mixed Perc_ProblemRaisedbyState FormerFrench  services Route N_Problems  if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store State2
	estadd local  C  "Yes"

mixed Perc_Problems_Discussed  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store Discuss
	estadd local  C  "Yes"
mixed Perc_Problems_Discussed FormerFrench services Route N_Problems  if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store Discuss2
	estadd local  C  "Yes"

mixed Perc_Problems_Project  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store Project
	estadd local  C  "Yes"
mixed Perc_Problems_Project FormerFrench services Route N_Problems  if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store Project2
	estadd local  C  "Yes"

mixed Perc_CommMaindOeuvre  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store CommMain
	estadd local  C  "Yes"
mixed Perc_CommMaindOeuvre FormerFrench services Route N_Problems  if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store CommMain2
	estadd local  C  "Yes"
	
esttab State State2 Discuss Discuss2  Project Project2 CommMain CommMain2  using "Tables Output/TableH2b.tex", replace /// ///
	scalars("C Controls") wide se b(2) star(** 0.05 *** 0.001) ///
	keep(FormerFrench) ///
   title("TABLE H2b: Village Problems & Problem-Solving, Full World Bank LSMS Sample")


mixed Perc_CommDons  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store CommDons
	estadd local  C  "Yes"
mixed Perc_CommDons  FormerFrench services Route N_Problems  if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store CommDons2
	estadd local  C  "Yes"

mixed Perc_CommMaterial  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store CommMaterial
	estadd local  C  "Yes"
mixed Perc_CommMaterial FormerFrench services Route N_Problems  if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store CommMaterial2
	estadd local  C  "Yes"

mixed Perc_Community_Contributions  FormerFrench   if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store CommContr
	estadd local  C  "Yes"
mixed Perc_Community_Contributions FormerFrench services Route N_Problems  if Max_CashCrop < 6 || Country: || RegionMerged:, cluster(Country)
	est store CommContr2
	estadd local  C  "Yes"

esttab CommDons CommDons2 CommMaterial CommMaterial2 CommContr CommContr2 using "Tables Output/TableH2c.tex", replace /// ///
	scalars("C Controls") wide se b(2) star(** 0.05 *** 0.001) ///
	keep(FormerFrench) ///
   title("TABLE H2c: Village Problems & Problem-Solving, Full World Bank LSMS Sample")
}

****** TABLE H4: Full Model Results of Figure 6: Collective Efficacy, Ghana Sample
{
use "Datasets/Ghana_Subnational_Final.dta", clear

label var Hance_cashcrop Cocoa_Exports
label var revCocoa_Suitability_Class Cocoa_Suitability

*South
mixed CollEff South if Wave == 1 || EA: || hhno: , robust
	est store South_1a
 estadd local  C  "Yes"
mixed CollEff South  if Wave == 3 || EA: || hhno: , robust
 est store South_3a
 estadd local  C  "Yes"

mixed CollEff South  assets Water_Quality Housing_Quality Female Age RespEduc  ELF if Wave == 1 || EA: || hhno: , robust
	est store South_1b
	estadd local  C  "Yes"
mixed CollEff South  assets Water_Quality Housing_Quality Female Age RespEduc  ELF Moved if Wave == 3 || EA: || hhno: , robust
	est store South_3b
	estadd local  C  "Yes"

* Cocoa Exports
mixed CollEff Hance_cashcrop  if Wave == 1 || EA: || hhno: , robust
	est store Hance_1a
	 estadd local  C  "Yes"
mixed CollEff Hance_cashcrop  if Wave == 3 || EA: || hhno: , robust
	est store Hance_3a
	 estadd local  C  "Yes"
 
mixed CollEff Hance_cashcrop assets Water_Quality Housing_Quality Female Age RespEduc  ELF if Wave == 1 || EA: || hhno: , robust
	est store Hance_1b
	estadd local  C  "Yes"
mixed CollEff Hance_cashcrop assets Water_Quality Housing_Quality Female Age RespEduc  ELF Moved if Wave == 3 || EA: || hhno: , robust
	est store Hance_3b
	estadd local  C  "Yes"

* Cocoa Suitability
mixed CollEff  revCocoa_Suitability_Class   if Wave == 1 || EA: || hhno: , robust
	est store Cocoa_1a
	estadd local  C  "Yes"
mixed CollEff  revCocoa_Suitability_Class  if Wave == 3 || EA: || hhno: , robust
	est store Cocoa_3a
	estadd local  C  "Yes"

mixed CollEff  revCocoa_Suitability_Class  assets Water_Quality Housing_Quality Female Age RespEduc  ELF if Wave == 1 || EA: || hhno: , robust
	est store Cocoa_1b
	estadd local  C  "Yes"
mixed CollEff  revCocoa_Suitability_Class  assets Water_Quality Housing_Quality Female Age RespEduc  ELF Moved if Wave == 3 || EA: || hhno: , robust
	est store Cocoa_3b
	estadd local  C  "Yes"

esttab South_1a South_1b  South_3a South_3b Hance_1a Hance_1b Hance_3a Hance_3b Cocoa_1a Cocoa_1b Cocoa_3a Cocoa_3b using "Tables Output/TableH4.tex", replace /// ///
	scalars("C Controls") wide se b(3) star(** 0.05 *** 0.001) ///
	keep(South Hance_cashcrop revCocoa_Suitability_Class) ///
   title("TABLE H4: Full Model Results of Figure 6: Collective Efficacy, Ghana Sample")
}
